<template>
  <!-- 兑换卡 -->
  <view class="box">
    <view class="aibox">我的AI模型：{{mytxt}}</view>
    <view class="selectbox">请选择AI模型：</view>
    <view class="wire"></view>
    <view class="uni-px-5">
      <uni-data-checkbox selectedColor='#4193FE'  mode="button" v-model="semod" :localdata="admodel"  @change="judge"></uni-data-checkbox>
    </view>
    <view class="exhibition">
      {{extxt}}
  
    </view>
    <view class="">
      <button class="addmodel" @click="amend">确定</button>
    </view>
    
  </view>
</template>

<script>
  export default {
    onLoad() {
      this.getmymodel()
      this.getAllModel()
    },
    data() {
      return{
        myid:'',
        mytxt:'',
        admodel:[
       
        ],
        semod:'0',
        extxt:'',
        optid:'',
        opttxt:'',
      }
    },
    methods:{
      getmymodel() {
        uni.request({
        	url: getApp().globalData.apiDomain+'ai/myAIModel',
        	method: 'GET',
        	header: {
        		'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
        		'token': uni.getStorageSync('wbyun_token'),
            'wbapp':'weixin_mp_xbgy'
        	},
        	data: {},
        	dataType: 'json',
        	success:  res => {
            console.log(res.data.datas);
            this.semod = res.data.datas
        		this.myid = res.data.datas
        	},
        	fail: () => {},
        	complete: () => {
        	}
        });
        
      },
      getAllModel() {
        uni.request({
        	url: getApp().globalData.apiDomain+'/ai/getAllModel',
        	method: 'POST',
        	header: {
        		'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
        		'token': uni.getStorageSync('wbyun_token'),
            'wbapp':'weixin_mp_xbgy'
        	},
        	data: {},
        	dataType: 'json',
        	success:  res => {
            console.log(res);
            if(res.data.code == 200) {
              res.data.msg.map(item => {
                if(item.disabled == 1) {
                  item.disabled = true
                }else {
                  item.disabled = false
                }
                this.admodel.push({
                  text:item.name,
                  value:item.aiid,
                  alt:item.alt,
                  disabled:item.disabled
                })
                
                if(item.aiid == this.myid) {
                  console.log(item);
                  this.mytxt = item.name
                  this.extxt = item.alt
                }
              })
            }
            
        		
        	},
        	fail: () => {},
        	complete: () => {
        	}
        });
      },
      judge(e){
        console.log(e);
        if(e.detail.data.text == "国外模型4.0") {
           e.detail.data.alt = '模型先进、适合难度大的应用，价值1800元/年，须成为终身会员后，方可使用'
        }
 
        this.extxt = e.detail.data.alt
        this.optid = e.detail.data.value
        this.opttxt = e.detail.data.text
      },
      amend() {
        uni.request({
        	url: getApp().globalData.apiDomain+'/ai/updateModel',
        	method: 'POST',
        	header: {
        		'content-type': 'application/x-www-form-urlencoded', //自定义请求头信息
        		'token': uni.getStorageSync('wbyun_token'),
            'wbapp':'weixin_mp_xbgy'
        	},
        	data: {
            "id":this.optid
          },
        	dataType: 'json',
        	success:  res => {
            console.log(res);
            if(res.data.code == 200) {
              console.log(this.opttxt);
              this.mytxt = this.opttxt
              uni.showToast({
              	title:res['data']['msg'],   
              	icon: 'none'
              });
             
            }else if(res.data.code == 506) {
              uni.showToast({
              	title:res['data']['msg'],   
              	icon: 'none',
              });
              setTimeout(() => {
                uni.navigateTo({
                  url: './task',
                });
              },1500)
            }else {
              uni.showToast({
              	title:res['data']['msg'],   
              	icon: 'none',
              });
            }
            
        		
        	},
        	fail: () => {},
        	complete: () => {
        	}
        });
      }
    }
  }
</script>

<style>
  .box {
    width: 95%;
    margin: auto;
    font-size: 35rpx;
    
  }
  .aibox {
    width: 100%;
    display: flex;
    justify-content: center;
    margin-top: 80rpx;
  }
  .selectbox {
    margin-top: 40rpx;
  }
  .wire {
    width: 100%;
    height: 1rpx;
    border: 1rpx solid #ccc;
    margin-top: 40rpx;
  }
  .uni-px-5 {
    margin-top: 50rpx;
    margin-left: 90rpx;
  }
  .exhibition {
    width: 100%;
    margin-top: 40rpx;
    text-align: center;
  }
  .addmodel {
    margin-top: 50rpx;
    background-color: #4193FE;
    border: 0;
    color: #fff;
  }
.uni-data-checklist .checklist-group .checklist-box.is--button {
        padding: 10px !important;
        width: 300rpx;
        display: flex;
        justify-content: center;
  }
  .uni-px-5 {
    margin-left: 0;

  }
  .uni-data-checklist .checklist-group{
    
    justify-content: space-around; 
  }
  .uni-data-checklist .checklist-group .checklist-box {
    margin-right: 0 !important;
  }
</style>